<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page import="java.util.Date" %> 
<%@ page import="java.text.DateFormat" %> 
<%@ page import="java.text.SimpleDateFormat" %> 

<%
	
	try 
	{
		String connectionURL = "jdbc:mysql://localhost:3306/unilearn";
 
		int row_count = 0;
		Boolean check_flag = false;
		Connection connection = null;
		ResultSet rs=null;
		Statement stmt = null;
		Statement stmt1 = null;
		
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		connection = DriverManager.getConnection(connectionURL, "root", "");
		stmt = connection.createStatement();
 
		if(!connection.isClosed())
		{
			String _scheme_id = "";
			String _mark = "";
			String str_tblCount = request.getParameter("datRowCount");
			String str_assignment_id = request.getParameter("datAssignmentID");
			String str_assignment_sub_id = request.getParameter("datAssignmentSubID");
			String str_assignment_name = request.getParameter("datAssignmentName");
			
			Double ttl_mark = 0.00;
			int tbl_count = Integer.parseInt(str_tblCount.trim());
			int _assignment_id = Integer.parseInt(str_assignment_id);
			int _assignment_sub_id = Integer.parseInt(str_assignment_sub_id);
	
			for(int i = 0; i < tbl_count; i++)
			{
				_scheme_id = request.getParameter("datAssMarkSchemeID" + i);
				_mark = request.getParameter("txtMarks" + i);
				int mark = Integer.parseInt(_mark.trim());

				row_count = stmt.executeUpdate("INSERT INTO assignment_mark (assignment_sub_id , assignment_id, ass_mark_scheme_id, mark)" 
				+ "VALUES ('"+str_assignment_sub_id+"', '"+str_assignment_id+"', '"+_scheme_id+"', '"+_mark+"')");
				
				ttl_mark = ttl_mark + mark;
				
				if(row_count <= 0){
					check_flag = true;
					break;
				}
			}
			
			if(!check_flag){
				stmt.executeUpdate("UPDATE assignment_submission SET mark = " + ttl_mark + "WHERE assignment_sub_id = " + str_assignment_sub_id);
				//out.println( "<script>alert('Create Successful')</script>" );
				response.sendRedirect("assignmentMarkDetail.jsp?assignmentSubID=" + str_assignment_sub_id + "&assignmentName=" + str_assignment_name);
			}
			else{
				out.println( "<script>alert('Create Failed')</script>" );
			}
				
		}
	}catch(Exception ex){
		out.println(ex);
	}
%>